sum of absolute differences in a sorted array